<?php
	class imageControl extends commonControl{
		function index(){
			$db = M("img");
			$rows = $db->findall();
			$this->assign("rows",$rows);
			$this->display();
		}

		function add_show(){
			$this->display();
		}

		function add(){				
			$upload = new upload();
			$db = M("img");
			$info = $upload -> upload();
			foreach($info as $k => $v){
				$_POST["pic"] =  $v["path"];
			}
			$adds = $db->add();
			if($info && $adds){
				$this->success("上传成功");
			}else{
				$this->error("上传失败");
			}

		}

		function edit_show(){
			$db = M("img");
			$id = $_GET["id"];
			$row = $db -> find($id);
			$this -> assign("row",$row);
			$this -> display();
		}

		function edit(){
			$upload = new upload();
			$db = M("img");
			$info = $upload -> upload();
			foreach($info as $k => $v){
				$_POST["pic"] = $v["path"];
			}
			$adds = $db->update($_POST);
			if($info && $adds){
				$this->success("更改成功","index");
			}else{
				$this->error("更改失败");
			}
		}

		function del(){
			$id = $_GET["id"];
			$db = M("img");
			$row = $db -> find($id);
			if($db->del($id)){
				$this->success("删除成功");
			}else{
				$this->error("删除失败");
			}
		}


	}
?>